home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1999 Eric Roccasecca. All rights reserved.
- // Based on Sillyballs, Copyright (C) 1988 Apple Computer, Inc.
-
- #include "X_Ray.h"
-
- #define BallWidth 20
- #define BallHeight 20
- #define BobSize 8
-
- Rect windRect;
- WindowPtr main1Ptr;
- WindowPtr main2Ptr;
- WindowPtr main3Ptr;
- Boolean gDone = false;
- Boolean isBig = false;
-
- void Initialize(void);
- void MakeWindows (void);
- void NewBall(void);
-
- int main(void)
- {
- OSErr err;
- EventRecord theEvent;
- GrafPtr curPort;
-
- Initialize();
- err = InitTransparentWindows();
- MakeWindows();
-
- while (!gDone)
- {
- WaitNextEvent (everyEvent, &theEvent, 10, nil);
- if (theEvent.what == keyDown)
- {
- if ((theEvent.message & charCodeMask) == ' ')
- {
- GetPort (&curPort);
-
- SetPort (main2Ptr);
- EraseRect (&main2Ptr->portRect);
- SetPort (main1Ptr);
- EraseRect (&main1Ptr->portRect);
- SetPort (main3Ptr);
- EraseRect (&main3Ptr->portRect);
-
- SetPort (curPort);
- }
- else if ((theEvent.message & charCodeMask) == '1') // erase window one
- {
- GetPort (&curPort);
- SetPort (main1Ptr);
- EraseRect (&main1Ptr->portRect);
- SetPort (curPort);
- }
- else if ((theEvent.message & charCodeMask) == '2') // erase window two
- {
- GetPort (&curPort);
- SetPort (main2Ptr);
- EraseRect (&main2Ptr->portRect);
- SetPort (curPort);
- }
- else if ((theEvent.message & charCodeMask) == '3') // erase window three
- {
- GetPort (&curPort);
- SetPort (main3Ptr);
- EraseRect (&main3Ptr->portRect);
- SetPort (curPort);
- }
- else if ((theEvent.message & charCodeMask) == 'a') // bring window 1 to front
- SelectWindow (main1Ptr);
- else if ((theEvent.message & charCodeMask) == 's') // bring window 2 to front
- SelectWindow (main2Ptr);
- else if ((theEvent.message & charCodeMask) == 'd') // bring window 3 to front
- SelectWindow (main3Ptr);
- else if ((theEvent.message & charCodeMask) == 'b') // toggle window 3 size
- {
- if (isBig)
- {
- SizeWindow (main3Ptr, (main3Ptr->portRect.right - main3Ptr->portRect.left) - 50, (main3Ptr->portRect.bottom - main3Ptr->portRect.top) - 50, false);
- isBig = false;
- }
- else
- {
- SizeWindow (main3Ptr, (main3Ptr->portRect.right - main3Ptr->portRect.left) + 50, (main3Ptr->portRect.bottom - main3Ptr->portRect.top) + 50, false);
- isBig = true;
- }
- }
- else if ((theEvent.message & charCodeMask) == 'q') // quit
- gDone = true;
- }
- else if (theEvent.what == mouseDown)
- {
- short foundWindPart;
- WindowPtr foundWind;
-
- foundWindPart = FindWindow (theEvent.where, &foundWind);
- if (foundWind)
- {
- if (foundWindPart == inDrag)
- DragWindow (foundWind, theEvent.where, &(*LMGetGrayRgn())->rgnBBox);
- else if (foundWindPart == inContent)
- SelectWindow (foundWind);
- }
- }
- else if (theEvent.what == updateEvt)
- {
- GetPort (&curPort);
- SetPort ((WindowPtr)theEvent.message);
-
- BeginUpdate ((WindowPtr)theEvent.message);
- EraseRect (&((WindowPtr)theEvent.message)->portRect);
- EndUpdate ((WindowPtr)theEvent.message);
-
- SetPort (curPort);
- }
- else if (theEvent.what == nullEvent)
- {
- GetPort (&curPort);
-
- if (curPort == main1Ptr)
- SetPort (main2Ptr);
- else if (curPort == main2Ptr)
- SetPort (main3Ptr);
- else if (curPort == main3Ptr)
- SetPort (main1Ptr);
-
- NewBall();
- }
- }
-
- DisposeTransparentWindow (main1Ptr);
- DisposeTransparentWindow (main2Ptr);
- DisposeTransparentWindow (main3Ptr);
-
- return 0;
- }
-
- void MakeWindows (void)
- {
- OSErr error;
-
- SetRect (&windRect, 50, 50, 250, 250);
- main1Ptr = NewTransparentWindow (nil, &windRect, "\pTransparent 1", true, documentProc, (WindowPtr) -1, false, 0, nil, nil, &error);
- OffsetRect (&windRect, 50, 50);
- main2Ptr = NewCWindow (nil, &windRect, "\pNormal 2", true, documentProc, (WindowPtr) -1, false, 0);
- //main2Ptr = NewTransparentWindow (nil, &windRect, "\pTransparent 2", true, documentProc, (WindowPtr) -1, false, 0, nil, nil, &error);
- OffsetRect (&windRect, 50, 50);
- main3Ptr = NewTransparentWindow (nil, &windRect, "\pTransparent 3", true, documentProc, (WindowPtr) -1, false, 0, nil, nil, &error);
-
- SetPort (main1Ptr);
- TextSize (BobSize);
- }
-
-
- void Initialize (void)
- {
- InitGraf (&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs (nil);
- InitCursor();
-
- GetDateTime((unsigned long*) &qd.randSeed);
- }
-
-
- void NewBall(void)
- {
- RGBColor ballColor;
- Rect ballRect;
- long int newLeft,
- newTop;
- GrafPtr curPort;
-
- GetPort (&curPort);
-
- if (curPort == main1Ptr)
- {
- ballColor.red = 0xFFFF;
- ballColor.green = 0;
- ballColor.blue = 0;
- }
- else if (curPort == main2Ptr)
- {
- ballColor.red = 0;
- ballColor.green = 0;
- ballColor.blue = 0xFFFF;
- }
- else if (curPort == main3Ptr)
- {
- ballColor.red = 0;
- ballColor.green = 0xFFFF;
- ballColor.blue = 0;
- }
-
- RGBForeColor (&ballColor);
-
- newTop = Random();
- newLeft = Random();
- newTop = ((newTop+32767) * windRect.bottom)/65536;
- newLeft = ((newLeft+32767) * windRect.right)/65536;
- SetRect (&ballRect, (short)newLeft, (short)newTop, (short)(newLeft+BallWidth), (short)(newTop+BallHeight));
-
- MoveTo ((short)newLeft, (short)newTop);
- PaintOval (&ballRect);
- }
-